home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 423_01 / recio200 / _rcgetf.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-15  |  3.3 KB  |  84 lines

  1. /*****************************************************************************
  2.    MODULE: _rcgetf.h
  3.   PURPOSE: recio column delimited floating point input functions
  4. COPYRIGHT: (C) 1994 William Pierpoint
  5.   VERSION: 2.00
  6.   RELEASE: April 15, 1994
  7. *****************************************************************************/
  8.  
  9. #ifndef _RCGETF_H
  10. #define _RCGETF_H
  11.  
  12. #include "recio.h"
  13.  
  14. extern int _rstatus(REC *rp, int mode);
  15. extern char *_rfldstr(REC *rp, size_t len);
  16. extern char *_rerrs(REC *rp, int errnum);
  17.  
  18. #define rcol(rp) (rp->r_colno)
  19. #define READ 0
  20.  
  21. /* clip value v between lower l and upper u bounds */
  22. #define range(l, v, u)  (min(max((l),(v)),(u)))
  23.  
  24. /* macro to get column delimited floating point number */
  25. #define rcget_fn( /* define function to get number from record */\
  26.     fn_type,      /* defined function return type */\
  27.     fn_name,      /* defined function name */\
  28.     fn_err,       /* defined function error return value */\
  29.     cv_type,      /* conversion function return type */\
  30.     cv_name,      /* conversion function name */\
  31.     fn_negmin,    /* inclusive valid negative minimum value */\
  32.     fn_negmax,    /* inclusive valid negative maximum value */\
  33.     fn_posmin,    /* inclusive valid positive minimum value */\
  34.     fn_posmax)    /* inclusive valid positive maximum value */\
  35. \
  36. fn_type fn_name(        /* return fn_type, return fn_err on error */\
  37.         REC *rp,        /* record pointer */\
  38.         size_t begcol,  /* field inclusive beginning column */\
  39.         size_t endcol)  /* field inclusive ending column */\
  40. { \
  41.     fn_type result=(fn_err); /* result to return */\
  42.     cv_type val;             /* conversion value */\
  43.     char *fldptr;            /* pointer to field string */\
  44.     char *endptr;            /* pointer to first invalid field char */\
  45.     char *fldp;              /* another pointer to field string */\
  46. \
  47.     if (!_rstatus(rp, READ)) { \
  48.       if (endcol >= begcol && begcol >= rbegcolno(rp)) { \
  49.         rcol(rp) = begcol - rbegcolno(rp); \
  50.         fldptr = _rfldstr(rp, endcol-begcol+1); \
  51.         if (fldptr) { \
  52.           for (;;) { \
  53.             for (fldp=fldptr; *fldp; fldp++) {if (!isspace(*fldp)) break;} \
  54.             if (*fldp) { \
  55.               endptr = fldptr; \
  56.               val = cv_name(fldptr, &endptr); \
  57.               while (isspace(*endptr)) endptr++; \
  58.               if (errno==ERANGE || !*endptr) { \
  59.                 if (!errno) { \
  60.                   if (!val || (val>=(fn_negmin) && val<=(fn_negmax)) || \
  61.                               (val>=(fn_posmin) && val<=(fn_posmax))) { \
  62.                         result = (fn_type) val; \
  63.                         goto done; \
  64.                   } \
  65.                 } /* out of range */ \
  66.                 fldptr = _rerrs(rp, R_ERANGE); \
  67.                 if (fldptr) { continue; } else { goto done; } \
  68.               } /* invalid data */ \
  69.               fldptr = _rerrs(rp, R_EINVDAT); \
  70.               if (fldptr) { continue; } else { goto done; } \
  71.             } /* missing data (empty fldstr) */ \
  72.             fldptr = _rerrs(rp, R_EMISDAT); \
  73.             if (fldptr) { continue; } else { goto done; } \
  74.           } \
  75.         } /* null pointer */ \
  76.       } /* column args reversed or tried to start before first column */ \
  77.       rseterr(rp, R_EINVAL); \
  78.     } \
  79. done: \
  80.     return result; \
  81. }
  82.  
  83. #endif
  84.